import redis


class RCon:
    def __init__(self):
        self.r = redis.Redis(host='localhost', port=6379, db=1)

    # 存入字符串
    def set_str(self, key, v, t):
        # 设置过期时间
        self.r.setex(key, t, v)

    # 取字符串
    def get_str(self, key):
        # 获取value
        value = self.r.get(key)
        # 如果有转换成字符串
        if value:
            value = str(self.r.get(key), encoding='utf8')
        return value


r = RCon()